const express = require('express');
const multer = require('multer');
const fs = require('fs');
const pathLib = require('path');

var objMulter = new multer({dest : "../www/upload/"});
var server = new express();
server.listen(8888);

server.use(objMulter.any());

server.post('/upload', function(req, res) { //解析文件，重命名并放到upload目录下面
    console.log('request: ', req);
    console.log(req.files); 

    var newname = req.files[0].path + pathLib.parse(req.files[0].originalname).ext;
    fs.rename(req.files[0].path, newname, function(error, data) {
        if (error) {
            res.send('上传失败');
        }else {
            res.send('上传成功');
        }
    });

});